//
//  NSTimer + tyBlock.h
//  tyFoundation
//
//  Created by qihongru on 14/10/31.
//  Copyright (c) 2014年 ND. All rights reserved.
//

#import <Foundation/Foundation.h>

/** An NSTimer Extension that runs a block when the timer is fired.
 
 Blocks are frequently more convenient to use instead of callbacks. They appear in the same context as the code that calls
 them and, and it's easier to pass state information to them at the same time.
 
 This extension creates two methods, one which creates an optionally repeating timer which fires a block, and the other creates
 a repeating timer but fire events is not configured.
 
 */

typedef void(^HandleTimerBlock)();

@interface NSTimer (TYBlock)

/* Create an optionally repeating timer with a block to run when the timer is fired.
 * @return An NSTimer that will fire events as configured.
 * @param seconds NSInterval. The number of seconds between the the firing of the timer.
 * @param repeats BOOL. Whether the timer should be repeating or not.
 * @param block A block which has a void return and takes no paramaters. This is run whenever the timer fires.
 */

+ (NSTimer *)ty_scheduledTimerWithTimeInterval:(NSTimeInterval)seconds block:(HandleTimerBlock)block repeats:(BOOL)inRepeats;

/* Create an optionally repeating timer with a block to run when the timer is fired.
 *
 * @return An NSTimer that fire events is not configured.
 *
 * @param seconds NSInterval. The number of seconds between the the firing of the timer.
 * @param repeats BOOL. Whether the timer should be repeating or not.
 * @param block A block which has a void return and takes no paramaters. This is run whenever the timer fires.
 */
+ (NSTimer *)ty_timerWithTimeInterval:(NSTimeInterval)seconds block:(HandleTimerBlock)block repeats:(BOOL)inRepeats;

@end

